//获取登录和注册盒子以及超链接
const registerBox = document.querySelector(".register");
const loginBox = document.querySelector(".login");
const loginA = document.querySelector(".login-a");
const registerA = document.querySelector(".register-a");
//登录转注册
loginA.addEventListener("click", () => {
    loginBox.style.display = "none";
    registerBox.style.display = "block"
})
//注册转登录
registerA.addEventListener("click", () => {
    registerBox.style.display = "none";
    loginBox.style.display = "block";
})
//测试ajax
// axios.get('/student/list').then(res => {console.log(res)});
//为表单绑定添加提交事件
registerBox.querySelector("form").addEventListener("submit", function (e) {
    e.preventDefault();
    //获取表单数据
    const data = $(this).serialize();
    axios.post("/api/register", data).then((result) => {
        if (result.data.code === 0) {
            toastr.success(result.data.message);
            registerA.click();
        }
    })
})
//为登录表单添加提交事件
loginBox.querySelector("form").addEventListener("submit",function(e){
    e.preventDefault();
    //获取表单数据
    const data =$(this).serialize();
    axios.post("/api/login",data).then((reulst=>{
        if(reulst.data.code===0){
            localStorage.setItem("liuxinKey",reulst.data.token)
            toastr.success(reulst.data.message);
            // console.dir(reulst)
            setTimeout(function(){
               location.href="./index.html";
            },1500)
        }
        console.log(reulst);
    }))
})